package game;

import java.awt.*;
import java.awt.image.BufferedImage;

public class ScoreBoard {
    private BufferedImage[] numImgs = new BufferedImage[10];

    public ScoreBoard(){
        for (int i = 0; i < 10; i++) {
            numImgs[i] = ImageManager.loadImage("src/images/"+ GameData.Skin +"/num"+i+".png");
        }
    }
    public void drawScore(Graphics g ,int highest_score,int current_score){
        drawHighestScore(g,highest_score);
        drawCurrentScore(g,current_score);
    }
    public void addScore() {
        if (GameData.gameTime % 960 == 0) {
            GameData.gameTime = 0;
            GameData.current_score++;
            if (GameData.current_score >= GameData.highest_score) {
                GameData.highest_score = GameData.current_score;
            }
            if (GameData.current_score %10 == 0){
                GameManager.getInstance().gameSound.score.PlaySound();
            }
        }
    }
    Font font14 = new Font(null,Font.BOLD,14);
    private void drawHighestScore(Graphics g,int score){
        int index0 = score/10000;//万位
        int index1 = score%10000/1000;//千位
        int index2 = score%1000/100;//百位
        int index3 = score%100/10;//十位
        int index4 = score%10;//个位

        g.setFont(font14);
        g.setColor(GameData.color);
        g.drawString("最高分：",0,16);

        g.drawImage(this.numImgs[index0],60,5,this.numImgs[index0].getWidth(),this.numImgs[index0].getHeight(),null);
        g.drawImage(this.numImgs[index1],60+10,5,this.numImgs[index1].getWidth(),this.numImgs[index1].getHeight(),null);
        g.drawImage(this.numImgs[index2],60+20,5,this.numImgs[index2].getWidth(),this.numImgs[index2].getHeight(),null);
        g.drawImage(this.numImgs[index3],60+30,5,this.numImgs[index3].getWidth(),this.numImgs[index3].getHeight(),null);
        g.drawImage(this.numImgs[index4],60+40,5,this.numImgs[index4].getWidth(),this.numImgs[index4].getHeight(),null);
    }
    private void drawCurrentScore(Graphics g,int score) {
        int index0 = score/10000;//万位
        int index1 = score%10000/1000;//千位
        int index2 = score%1000/100;//百位
        int index3 = score%100/10;//十位
        int index4 = score%10;//个位

        g.drawImage(this.numImgs[index0],530,5,this.numImgs[index0].getWidth(),this.numImgs[index0].getHeight(),null);
        g.drawImage(this.numImgs[index1],530+10,5,this.numImgs[index1].getWidth(),this.numImgs[index1].getHeight(),null);
        g.drawImage(this.numImgs[index2],530+20,5,this.numImgs[index2].getWidth(),this.numImgs[index2].getHeight(),null);
        g.drawImage(this.numImgs[index3],530+30,5,this.numImgs[index3].getWidth(),this.numImgs[index3].getHeight(),null);
        g.drawImage(this.numImgs[index4],530+40,5,this.numImgs[index4].getWidth(),this.numImgs[index4].getHeight(),null);
    }




}
